/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.context;

import com.context.properties.ContextProperties;
import java.io.File;
import java.io.IOException;
import util.file.FileUtil;
import util.log.MiLoggerFile;

/**
 *
 * @author Rdelacruz
 */
public class LoggerContext {
    
    private MiLoggerFile loggerCargaAutomatica;
    private MiLoggerFile loggerErrores;
    private MiLoggerFile loggerRequest;
    
        
    private final int LIMIT_SIZE = 5*1024*1024;// 5MB en bytes
    //private final int LIMIT_SIZE = 1024;    
    private final int COUNT_MAX = 1000;//Como maximo 1000 archivos de 5MB    
    
    /*
    public static MiLogger getLogger(HttpServletResponse response) {
        return MiLogger.getLogger(response, loggerErrores);
    }*/
    
    public LoggerContext() {
        
    }

    public void inicializar() throws Exception, IOException, IOException, IOException {
        ContextProperties cp = AppContext.getInstancia().getContextProperties();
        
        FileUtil.crearDirectorioSiNoExiste(cp.getDirectorio_log(),false);
                
        File fileLog = new File(cp.getDirectorio_log(),"carga_automatica.log");
        File fileErrorLog = new File(cp.getDirectorio_log(),"errores.log");
        File fileRequestLog = new File(cp.getDirectorio_log(),"request.log");
        
        loggerCargaAutomatica = new MiLoggerFile();
        loggerErrores = new MiLoggerFile();
        loggerRequest = new MiLoggerFile();
                
        loggerCargaAutomatica.inicializar("CargaAutomatica",fileLog,LIMIT_SIZE, COUNT_MAX, true);
        loggerErrores.inicializar("Errores",fileErrorLog,LIMIT_SIZE, COUNT_MAX, true);
        loggerRequest.inicializar("Request",fileRequestLog,LIMIT_SIZE, COUNT_MAX, true);
    }
    
    public void finalizar() {
        loggerCargaAutomatica.finalizar();
        loggerErrores.finalizar();
        loggerRequest.finalizar();
    }

    public MiLoggerFile getLoggerCargaAutomatica() {
        return loggerCargaAutomatica;
    }

    public MiLoggerFile getLoggerErrores() {
        return loggerErrores;
    }

    public MiLoggerFile getLoggerRequest() {
        return loggerRequest;
    }
    
    
}
